package org.come.control;

import org.come.Frame.ZhuFrame;
import org.come.action.FromServerAction;
import org.come.bean.ChangeRoleNameBean;
import org.come.socket.GameClient;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.GsonUtil;

import com.tool.image.ImageMixDeal;
import com.tool.image.ManimgAttribute;
import com.tool.role.RoleData;

/**
 * 修改名称
 *
 * @author Administrator
 *
 */
public class ChangerolenameControl implements FromServerAction {

	@Override
	public void controlMessFromServer(String mes, String type) {
		// TODO Auto-generated method stub
		// 接受改名
		ChangeRoleNameBean nameBean = GsonUtil.getGsonUtil().getgson().fromJson(mes, ChangeRoleNameBean.class);
		if (!nameBean.isFlag()) {
			ZhuFrame.getZhuJpanel().addPrompt2("你修改的名称已被其他玩家使用");
			return;
		}
		if (nameBean.getOldName().equals(ImageMixDeal.userimg.getRoleShow().getRolename())) {
			ImageMixDeal.userimg.getRoleShow().setRolename(nameBean.getNewName());
			ImageMixDeal.userimg.setName(nameBean.getNewName());
			ImageMixDeal.username = nameBean.getNewName();
			RoleData.getRoleData().getLoginResult().setRolename(nameBean.getNewName());
			GoodsListFromServerUntil.Uerbiaoid(nameBean.getRgid());
//			TestMain.gameJframe.setTitle(GameClient.BT+"  " + ImageMixDeal.username + " ID:" + ImageMixDeal.userimg.getRoleShow().getRole_id());
		} else {
			ManimgAttribute manimgAttribute = ImageMixDeal.Playerimgmap.get(nameBean.getOldName());
			manimgAttribute.setName(nameBean.getNewName());
			// 修改结婚对象的名字
			String marry=RoleData.getRoleData().getLoginResult().getMarryObject();
			if (marry!=null&&marry.equals(nameBean.getOldName())) {
				RoleData.getRoleData().getLoginResult().setMarryObject(nameBean.getNewName());
			}
			ImageMixDeal.Playerimgmap.put(nameBean.getNewName(), manimgAttribute);
			ImageMixDeal.Playerimgmap.remove(nameBean.getOldName());
		}
	}
}
